from tools_algorithm import *


class Solution:
    def maxPointsInsideSquare(self, points: List[List[int]], s: str) -> int:
        h = {}
        smn = inf
        for i, (x, y) in enumerate(points):
            c = s[i]
            dist = max(abs(x), abs(y))
            if c not in h:
                h[c] = [dist, inf]
            else:
                if dist < h[c][0]:
                    h[c][1] = h[c][0]
                    h[c][0] = dist
                elif dist < h[c][1]:
                    h[c][1] = dist
                smn = min(smn, h[c][1])
        ans = 0
        for k, v in h.items():
            if v[0] < smn:
                ans += 1
        return ans


s = Solution()
print(
    s.maxPointsInsideSquare(
        points=[[2, 2], [-1, -2], [-4, 4], [-3, 1], [3, -3]], s="abdca"
    )
)
